﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class gold_eGoldYDDP : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
            DateTime dtDate = System.DateTime.Now.Date;

            var goods = dal.eGold_YDDP.Select(x => new { x.id, x.code, x.name, x.zx, x.zd, x.zljm, x.hsl, x.comment, x.createdate });
            goods = goods.Where(x => x.createdate == dtDate);
            Repeater1.DataSource = goods;
            Repeater1.DataBind();

        }
    }
    protected void bt_addgoods_Click(object sender, EventArgs e)
    {
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        string strId = this.code.Text;
        string strName = this.name.Text;
        Decimal dbZx = Convert.ToDecimal(this.zx.Text);
        Decimal dbZd = Convert.ToDecimal(this.zd.Text);
        Decimal dbZljm = Convert.ToDecimal(this.zljm.Text);
        dbZljm = dbZljm / 10000;
        Decimal dbHsl = Convert.ToDecimal(this.hsl.Text);
        string strComment = this.comment.Text;
        DateTime dtToday = System.DateTime.Now.Date;

          //$("#code").val(json[0].C);
          //            $("#name").val(json[0].N);
          //            $("#zx").val(json[0].L);
          //            $("#zd").val(json[0].D);
          //            $("#zljm").val(json[0].AV);
          //            $("#hsl").val(json[0].D);

        dal.eGold_YDDP.AddObject(new CMSModel.eGold_YDDP
        {
            code = strId,
            name = strName,
            zx = dbZx,
            zd = dbZd,
            zljm = dbZljm,
            hsl = dbHsl,
            comment = strComment,
            createdate = dtToday
        });
        try
        {
            dal.SaveChanges();
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('新增成功');document.location='eGoldYDDP.aspx'", true);
        }
        catch (Exception ex)
        {
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('" + ex.Message.ToString() + "');", true);
        }
    }
    protected void Delete_Click(object sender, EventArgs e)
    {
        int id = int.Parse(this.hid_id.Value);

        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        CMSModel.eGold_YDDP goods = dal.eGold_YDDP.First(x => x.id == id);
        dal.DeleteObject(goods);
        try
        {
            dal.SaveChanges();
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('删除成功');document.location='eGoldYDDP.aspx'", true);
        }
        catch (Exception ex)
        {
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('" + ex.Message.ToString() + "');", true);
        }
    }
    protected void bt_modify_Click(object sender, EventArgs e)
    {
        int id = int.Parse(this.hid_id.Value);
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        CMSModel.eGold_YDDP goods = dal.eGold_YDDP.First(x => x.id == id);
        goods.comment = this.modify_comment.Text;
        dal.SaveChanges();
        ClientScript.RegisterStartupScript(GetType(), "aa", "alert('修改成功');document.location='eGoldYDDP.aspx'", true);
    }
}